/**
 * @Author: ls-mac
 * @Date:   2018-09-04T13:36:51+08:00
 * @Last modified by:   ls-mac
 * @Last modified time: 2020-03-08 18:16:46
 */

import { isUrl } from '../utils/utils';

const menuData = [
  {
    name: '订单维护',
    icon: 'file-text',
    path: 'Order',
    authority: '',
    children: [
      {
        name: '订单列表',
        path: 'order-list',
        authority: '',
        key: '00',
        target: '_blank',
      },
      {
        name: '后台下单',
        path: 'order-commit',
        authority: '',
        key: '01',
        target: '_blank',
      },
      {
        name: '体检报告',
        path: 'order-report',
        authority: '',
        key: '02',
        target: '_blank',
      },
    ],
  },
  {
    name: '体检合同',
    icon: 'file-text',
    path: 'Contract',
    authority: '',
    children: [
      {
        name: '合同列表',
        path: 'contract-list',
        authority: '',
        target: '_blank',
      },
    ],
  },
  {
    name: '企业管理',
    icon: 'file-text',
    path: 'Enterprise',
    authority: '',
    children: [
      {
        name: '企业列表',
        path: 'list',
        authority: '',
        target: '_blank',
      },
      {
        name: '企业可体检门店',
        path: 'company-storePage',
        authority: '',
        target: '_blank',
      },
      {
        name: '员工列表',
        path: 'employee-list',
        authority: '',
        target: '_blank',
      },
      {
        name: '家属列表',
        path: 'family-list',
        authority: '',
        target: '_blank',
      },
      {
        name: '体检套餐',
        path: 'package-list',
        authority: '',
        target: '_blank',
      },
      {
        name: '套餐加项',
        path: 'extraItem-list',
        authority: '',
        target: '_blank',
      },
      {
        name: '套餐服务',
        path: 'service-list',
        authority: '',
        target: '_blank',
      },
    ],
  },
  {
    name: '字典维护',
    icon: 'file-text',
    path: 'Dict',
    authority: '',
    children: [
      {
        name: '省份维护',
        path: 'province-list',
        authority: '',
        target: '_blank',
      },
      {
        name: '城市维护',
        path: 'city-list',
        authority: '',
        target: '_blank',
      },
      {
        name: '体检机构',
        path: 'institution-list',
        authority: '',
        target: '_blank',
      },
      {
        name: '体检门店',
        path: 'store-list',
        authority: '',
        target: '_blank',
      },
      {
        name: '门店特性',
        path: 'store-features',
        authority: '',
        target: '_blank',
      },
      {
        name: '门店不可预约时间',
        path: 'store-unavailableTimeList',
        authority: '',
        target: '_blank',
      },
    ],
  },
  {
    name: '系统管理',
    icon: 'file-text',
    path: 'System',
    authority: '',
    children: [
      {
        name: '管理员维护',
        path: 'admin-list',
        authority: '',
        target: '_blank',
      },
      {
        name: '角色管理',
        path: 'role-list',
        authority: '',
        target: '_blank',
      },
      {
        name: '节假日维护',
        path: 'vocation-list',
        authority: '',
        target: '_blank',
      },
    ],
  },
];

function formatter(data, parentPath = '/', parentAuthority) {
  return data.map(item => {
    let { path } = item;
    if (!isUrl(path)) {
      path = parentPath + item.path;
    }
    const result = {
      ...item,
      path,
      authority: item.authority || parentAuthority,
    };
    if (item.children) {
      result.children = formatter(item.children, `${parentPath}${item.path}/`, item.authority);
    }
    return result;
  });
}

export const getMenuData = () => formatter(menuData);
